<template>
    <div>
        <div>
            <div style="float:left">
                <Input style="width:250px" >
                <span slot="prepend">学院名称：</span>
                <Button slot="append" icon="ios-search" ></Button>
                </Input>
            </div>
    
            <Button-group>
                <Button >新增</Button>
                <Button >导出</Button>
            </Button-group>
        </div>
    
        <Table border stripe :columns="header" :data="data_list" size="small" ref="table" class="table" @on-row-click="rowClick"></Table>
  
        <Modal v-model="modal_del_status" title="删除一个学院" @on-ok="option_delete_save" @on-cancel="modal_cancel">
            <Form :model="temp_dele_data" :label-width="80">
                <p>您确定删除这个记录吗？</p>
    
            </Form>
        </Modal>
    
    </div>
</template>
<script>
export default {
    data() {
        return {

            //初始化url
            init_url: '/mes/core/smsSig/all?id=',
            //删除一行url
            del_url: '/mes/core/smsSig/baseAll?id=',

            //表格标题
            header: [
                {
                    type: 'index',
                    width: 60,
                    align: 'center'
                },
                {
                    "title": "签名信息",
                    "key": "signature",
                    "width": 120,
                    "sortable": true,
                },
                {
                    "title": "签名类型",
                    "key": "signatureType",
                    "width": 120,
                    "sortable": true
                },
                {
                    "title": "备注",
                    "key": "remark",
                    "width": 150,
                    "sortable": true
                },
                {
                    "title": '操作',
                    "min-width": 100,
                    "align": 'center',
                    render: (h, params) => {
                        return h('div', [          
                            h('Button', {
                                props: {
                                    type: 'error',
                                    size: 'small'
                                },
                                on: {
                                    click: () => {
                                        this.delete_show(params)
                                    }
                                }
                            }, '删除')
                        ]);
                    }
                }


            ],
            //表格数据源
            data_list: [],
           
            //删除modal对话框显示状态
            modal_del_status: false,
          
            //删除一行的临时数据
            temp_dele_data: {
                id: '',
                name: '',
                createTime: '',
                remark: ''
            },
            //删除一行的数据索引
            temp_dele_index: '',
        }
    },
    methods: {
        
        //modal对话框取消事件
        modal_cancel() {
            this.$Message.info('操作已经取消');
        },
      
        //删除按钮触发事件
        delete_show(params) {
            this.modal_del_status = true;
            this.temp_dele_data = params.row;
            this.temp_dele_index = params.index;
        },
       
        //删除一行操作
        option_delete_save() {
            var _self = this;
            this.$ajax.delete(_self.del_url + this.temp_dele_data.id, )
                .then(function (response) {
                    if (response) {
                        if (response.data.status == 'success') {
                            _self.$Message.info('删除成功');
                            _self.data_list.splice(_self.temp_dele_index, 1);
                            var index = _self.$stringUtil.getStringIndex(_self.data_cache_list,_self.temp_dele_data.id);
                            _self.data_cache_list.splice(index, 1);
                            return;
                        }
                    }
                    _self.$Message.info('删除失败');
                })
                .catch(function (error) {
                    console.log(error);
                });

        },
    
        
    },
    mounted() {

        var _self = this;

        //初始化表单数据
        // this.$ajax.get(_self.init_url)
        //     .then(function (response) {
        //         _self.data_list = response.data;
        //         _self.data_cache_list =  _self.data_list.slice();           
        //     })
        //     .catch(function (error) {
        //         console.log(error);
        //     });
    },
    props: ['appId'],
    watch: {
        appId: function (newValue, oldValue) {
            var _self = this;
            alert(newValue);
            //初始化表单数据
            this.$ajax.get(_self.init_url + newValue)
                .then(function (response) {
                    _self.data_list = response.data;
                    console.log(_self.data_list);
                })
                .catch(function (error) {
                    console.log(error);
                });
        }
    }

}
</script>

<style>
.btn-group {
    margin-bottom: 5px;
}
</style>
